package com.score.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.score.mapper.IRoleMapper;
import com.score.mapper.IUserMapper;
import com.score.pojo.TRole;
import com.score.pojo.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl {

    @Autowired
    private IUserMapper userMapper;

    @Autowired
    private IRoleMapper roleMapper;

    public TUser findByName(String username) {
        QueryWrapper<TUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return userMapper.selectOne(wrapper);
    }

    public TRole getAuthority(Integer id) {
        QueryWrapper<TRole> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id",id);
        return roleMapper.selectOne(wrapper);
    }

    public Integer changePasswd(String username, String password) {
        QueryWrapper<TUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        TUser tUser = userMapper.selectOne(wrapper);
        tUser.setPassword(password);
        return userMapper.updateById(tUser);
    }
}
